package com.pucong.gitee.database.backup.business.databaseTask.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pucong.gitee.database.backup.common.entity.database.BackupTask;
import com.pucong.gitee.database.backup.business.databaseTask.service.BackupTaskService;
import com.pucong.gitee.database.backup.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author pucong
 * @url https://gitee.com/pucong
 * @create 2020-06-23
 */
@RestController
@RequestMapping("/backup/task")
@Api(value = "备份任务信息-API ", tags = "2. 备份任务信息 API")
public class BackupTaskController {

    @Autowired
    private BackupTaskService backupTaskService;

    @GetMapping("/getTaskInfoListByPage/{pageNum}/{pageSize}")
    @ApiOperation(value = "201分页查询", notes = "分页条件查询")
    public Res<IPage<BackupTask>> getTaskInfoListByPage(@ApiParam(value = "页数",example = "1")@PathVariable("pageNum") int pageNum, @ApiParam(value = "一页大小",example = "10")@PathVariable("pageSize") int pageSize, BackupTask backupTask){
        IPage<BackupTask> backupTaskIPage = backupTaskService.getTaskInfoListByPage(pageNum,pageSize,backupTask);
        return Res.ok(backupTaskIPage);
    }

    @GetMapping("/getTaskInfoById/{id}")
    @ApiOperation(value = "202根据主键查询", notes = "根据主键查询")
    public Res<BackupTask> getTaskInfoById(@ApiParam("主键")@PathVariable("id") String id){
        BackupTask personInfo = backupTaskService.getTaskInfoById(id);
        return Res.ok(personInfo);
    }

    @PutMapping("/saveTask/{databaseId}")
    @ApiOperation(value = "203新增和修改", notes = "新增和修改")
    public Res<Integer> saveTask(@ApiParam("主键")@PathVariable("databaseId") String databaseId,@RequestBody BackupTask backupTask){
        int i = backupTaskService.saveTask(databaseId,backupTask);
        return Res.ok(i);
    }

}
